import json
import requests
import time
from datetime import datetime

def send_request_tufa(arg1):

    # json_data = {'text': arg1}
    json_data = arg1
    # t_start = datetime.now()
    # timeout 30秒
    request_res = requests.post('http://127.0.0.1:8080/text_classification/', json=json_data, timeout=1000).json()
    
    # t_end = datetime.now()
    # print("cost: %f seconds" %(t_end - t_start).total_seconds())
    if "code" in request_res and request_res["code"] == 200:
        print("success")
        print(json.dumps(request_res))
    else:
        # fali_count += 1
        print('fail')


if __name__ == '__main__':

    
    test_data = {
        "content":"【次紧急】市民来电反映:上述地址因交通事故导致川南奉公路中间的隔离带破损，水泥墩被撞至道路中，车辆通行存在安全隐患。诉求：希望管理部门尽快进行清理。（市民要回复）",
        }

            
    s = time.time()
    send_request_tufa(test_data)

    print("infer: {}".format(time.time() - s))